from dataclasses import dataclass
from typing import Tuple, Any
import os


@dataclass
class Configuration:
    base_dir: str = None
    save_path: str = None
    patch_dir: str = None
    model: str = 'resnet18'
    base_model: str = None
    classes: Tuple[str] = ('normal', 'tumor')
    image_size: int = 224
    crop_size: int = 224
    color_jitter_brightness: float = 32.0 / 255.0
    color_jitter_contrast: float = 0.5
    color_jitter_saturation: float = 0.5
    color_jitter_hue: float = 0.2
    normalize: bool = True
    hsv: bool = False
    pin_memory: bool = True
    num_workers: int = 0
    batch_size: int = 10
    lr: float = 0.01
    momentum: float = 0.9
    optimizer: str = 'adam'
    log_every: int = 10
    epoch: int = 1
    float16: bool = False

    def validate(self):
        for clz in self.classes:
            for t in ('train', 'valid'):
                if not os.path.isfile(os.path.join(self.base_dir, f'{clz}.{t}.list')):
                    raise FileNotFoundError(f'list file not found: {self.base_dir}/{clz}.{t}.list')
